<?php
include_once('common/header.php');			
if($AppUI->id <=0) {
	Vfriend_Function::redirect(HOST_VFRIEND);
}
$strRefer		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$strToken		= $objRequest->getParam('token','');
$intProductId	= $objRequest->getParam('productid',0);
$strSession		= Vfriend_Function::getSecret($intProductId, SE_PRODUCT_ADD_BASKET);
$intError		= 0;
$strProductName	= '';
if(Vfriend_Function::isValidLink($strRefer) && isset($strSession) && $strToken == $strSession && $intProductId) {
	Vfriend_Function::deleteSecret($intProductId, SE_PRODUCT_ADD_BASKET);
	$objProduct 	= new Product();
	$objVfriendUser = new Vfriend_User();
	$arrInfo		= $objProduct->get($intProductId);
	if(isset($arrInfo) && isset($arrInfo['statuses']) && $arrInfo['statuses']) {
		$intPrice		= isset($arrInfo['price']) ? $arrInfo['price'] : 0;
		$strProductName	= $arrInfo['name'];
		$intError 	= $objProduct->addBasket($AppUI->id,$intTargetId,$intProductId,$intPrice);
		if($intError == 0) {
			Vfriend_Function::setMsg($arrMessage[1]);
		} else {
			$intError += 2 ;
		}
	} else {
		$intError = 2;
	}
} else {
	$intError = 1;
}
if($intError > 0) {
	$strError = $arrError[$intError];
	$strError = str_replace('[strTarget]',$strTargetName, $strError);
	$strError = str_replace('[strProductName]',$strProductName, $strError);
	Vfriend_Function::setError($strError);	
}
Vfriend_Function::redirect(isset($strRefer) ? $strRefer : LINK_PRODUCT);
?>